//
//  ComScrollerView.m
//  TheRoadAD
//
//  Created by baixue on 16/8/19.
//  Copyright © 2016年 baixue. All rights reserved.
//

#import "ComScrollerView.h"
#import "ComChannelCell.h"
#import "ChooseCell.h"

#define TITLE @[@"美图秀秀",@"趣味视频",@"聚焦维权"]
#define MORE @[@"更多美图",@"更多视频",@"更多维权"]

@implementation ComScrollerView

-(id)initWithFrame:(CGRect)frame{
   self =  [super initWithFrame:frame];
    if (self) {
//        [self createUIwithframe:frame];
        [self setUpChannel];
        [self setUpChosen];
    }
    return self;
}


-(void)createUIwithframe:(CGRect)frame{
    _scrollerView = [[UIScrollView alloc]initWithFrame:frame];
    _scrollerView.delegate = self;
    _scrollerView.bounces = NO;
    _scrollerView.pagingEnabled = YES;
    _scrollerView.showsHorizontalScrollIndicator = NO;
    _scrollerView.showsVerticalScrollIndicator = NO;
    _scrollerView.contentSize = CGSizeMake(Screen_Width * 2 , 0);
    [self addSubview:_scrollerView];
  
}



//频道列表的tableView
-(void)setUpChannel{
    
    _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, Screen_Width, Screen_Height-50 -64)style:UITableViewStylePlain];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    _tableView.bounces = NO;
    //    _tableView.scrollEnabled = NO;
    [self addSubview:_tableView];
}
//精选列表的tableView
-(void)setUpChosen{
    _chosenTableView = [[UITableView alloc] initWithFrame:CGRectMake(Screen_Width, 0, Screen_Width, Screen_Height-50) style:UITableViewStylePlain];
    _chosenTableView.delegate = self;
    _chosenTableView.dataSource = self;
    _chosenTableView.bounces = NO;
    [_scrollerView addSubview:_chosenTableView];
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return TITLE.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    
    if (tableView == _tableView) {
        ComChannelCell *cell = [tableView dequeueReusableCellWithIdentifier:@"comChannel"];
        if (cell == nil) {
            cell = [[[NSBundle mainBundle] loadNibNamed:@"ComChannelCell" owner:nil options:nil] lastObject];
        }
        //indexPath.row ==1 趣味视频  播放按钮显示
        if (indexPath.row == 1) {
            cell.videoPlay1.hidden = NO;
            cell.videoPlay2.hidden = NO;
            cell.videoPlay3.hidden = NO;
            cell.videoPlay4.hidden = NO;
            cell.meitu1.image = [UIImage imageNamed:@"shipin1"];
            cell.meitu2.image = [UIImage imageNamed:@"shipin2"];
            cell.meitu3.image = [UIImage imageNamed:@"shipin3"];
            cell.meitu4.image = [UIImage imageNamed:@"shipin4"];
            cell.title1.text = @"永远的爱西西里";
            cell.title2.text = @"亚龙弯弯";
            cell.title3.text = @"西北莫带";
            cell.title4.text = @"拉维斯佳";
            
        }
        if (indexPath.row == 2) {
            cell.videoPlay1.hidden = NO;
            cell.videoPlay2.hidden = NO;
            cell.videoPlay3.hidden = NO;
            cell.videoPlay4.hidden = NO;
            cell.meitu1.image = [UIImage imageNamed:@"weiquan1"];
            cell.meitu2.image = [UIImage imageNamed:@"weiquan2"];
            cell.meitu3.image = [UIImage imageNamed:@"weiquan3"];
            cell.meitu4.image = [UIImage imageNamed:@"weiquan4"];
            cell.title1.text = @"维权1";
            cell.title2.text = @"维权2";
            cell.title3.text = @"维权3";
            cell.title4.text = @"维权吧";
        }
        cell.titleLable.text = TITLE[indexPath.row];
        [cell.IconPictures setTitle:MORE[indexPath.row] forState:UIControlStateNormal];
        cell.BlockMore = ^(){
            
            /**
             *  indexPath.row == 0  更多美图
             *  indexPath.row == 1  更多视频
             *  indexPath.row == 2  聚焦维权
             */
            if (indexPath.row == 0) {
                _ClickMore(101);
            }if (indexPath.row == 1) {
                
                _ClickMore(102);
            }if (indexPath.row == 2) {
                _ClickMore(103);
            }
            
        };
        
        
        return cell;
    }else {
        
        ChooseCell *cell = [tableView dequeueReusableCellWithIdentifier:@"choose"];
        if (cell == nil) {
            cell = [[[NSBundle mainBundle] loadNibNamed:@"ChooseCell" owner:nil options:nil] lastObject];
        }
        
        
        return cell;
    }
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (tableView == _tableView) {
        //        return 370 * Screen_Height/736;
        return Screen_Width * 40 / 319 + 180 * Screen_Width/319 + 100 * Screen_Width/319;
    }else
        return 270 * Screen_Height/736;
    
    
}

@end
